package com.daona.application.controller;

import com.daona.application.facade.PdfFacade;
import com.daona.application.kafka.Producer;
import com.daona.model.dto.query.PdfDataQuery;
import com.daona.model.message.PdfMessage;
import com.daona.model.view.PdfInfoView;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/pdf")
@RequiredArgsConstructor
public class PdfController {

    private final PdfFacade pdfFacade;

    private final Producer producer;

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public void parse2Pdf(HttpServletResponse response, @RequestBody PdfDataQuery dataQuery) throws Exception {
        pdfFacade.htmlToPdf(response, dataQuery);
        //return PdfInfoView.builder().name(dataQuery.getTemplateName()).build();
    }

    @RequestMapping(value = "/kafka/send", method = RequestMethod.POST)
    public Object generatePdf(@RequestBody PdfMessage message) {
        producer.sendMsg(message);
        //producer.sendMsg(PdfMessage.builder().key("pdf").messageId(1000L).content("创建调用报告").build());
        return PdfInfoView.builder().name("发送创建调用报告成功").build();
    }
}
